home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
036a
/
pmfinder.zip
/
PMFINDER.C
< prev
next >
Wrap
Text File
|
1991-12-05
|
25KB
|
763 lines
/*
* OS/2 PM File Finder Utility - GUI SOURCE CODE
*
* LANGUAGE : Microsoft C6.0
* MODEL : large - MT
* ENVIRONMENT : IBM OS/2 PM Toolkit v1.3
* STATUS : operational
*
* Adapted from KPW's Windows 2.1 version of 07/20/88.
*
* 11/01/88 1.00 - Jerry Weldon - initial creation.
* 03/22/91 1.10 - Robert Mahoney - added multi-threading.
* 11/25/91 1.20 - Robert Mahoney - added archive file search.
*
*/
/* This module contains the GUI code for the file finder */
#define INCL_DOSPROCESS
#define INCL_DOSNLS
#define INCL_WINWINDOWMGR
#define INCL_WINDIALOGS
#define INCL_WINBUTTONS
#define INCL_WINENTRYFIELDS
#define INCL_WINLISTBOXES
#define INCL_WINMENUS
#define INCL_WINFRAMEMGR
#define INCL_WINSYS
#define INCL_WINPOINTERS
#define INCL_GPILCIDS
#define NUL '\0'
#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <process.h>
#include "pmfinder.h"
/* global variables */
BOOL fContinue;
HAB hab; /* handle to anchor block */
ULONG ulWaitSem = 0; /* wait semaphore for threads*/
HSEM hsemWait = &ulWaitSem;
static USHORT usThreadCounter; /* number of threads */
/**/
/*
* main( VOID ) : VOID;
*
* This function is the system entry point for the application
* and is responsible for defining the appropriate window
* classes and for processing all the messages. Note how
* the dialog box manager is responsible for the operation of
* the file finder window.
*
*/
VOID cdecl main( VOID )
{
HMQ hmq; /* handle to message queue */
HWND hwnd; /* handle to main window */
HPOINTER hptr; /* handle to window's icon */
/* initialize thread & create message queue */
hab = WinInitialize( 0 );
hmq = WinCreateMsgQueue( hab, 0 );
/* load the main dialog */
hwnd = WinLoadDlg(
HWND_DESKTOP,
HWND_DESKTOP,
FinderDlgProc,
NUL,
ID_FINDER,
NUL
);
/* set an icon for the dialog */
hptr = WinLoadPointer( HWND_DESKTOP, NUL, ID_FINDER );
WinSendMsg( hwnd, WM_SETICON, (MPARAM)hptr, 0L );
/* process the dialog */
WinProcessDlg( hwnd );
/* destroy the dialog and its icon */
WinDestroyWindow( hwnd );
WinDestroyPointer( hptr );
/* destroy message queue & terminate thread */
WinDestroyMsgQueue( hmq );
WinTerminate( hab );
}
/**/
/*
* FinderDlgProc( hwnd, usMsg, mp1, mp2 ) : MRESULT;
*
* hwnd handle to main dialog window
* usMsg message number
* mp1 message parameter 1
* mp2 message parameter 2
*
* This function is responsible for processing all the messages
* which relate to the file finder dialog box. This mainly
* involves the definition and retrieval of the various
* events generated by the user.
*
*/
MRESULT EXPENTRY FinderDlgProc(
HWND hwnd,
USHORT usMsg,
MPARAM mp1,
MPARAM mp2 )
{
MRESULT mresRtnVal; /* function return value */
BOOL fPassToDef; /* pass to def window proc? */
static int iSaveLength;
static BOOL fSearch;
mresRtnVal = FALSE;
fPassToDef = FALSE;
switch ( usMsg ) {
case WM_INITDLG:
InitDlgBox(hwnd);
iSaveLength = 0;
fSearch = FALSE;
break;
case WM_CONTROL:
switch ( SHORT1FROMMP( mp1 ) ) {
case IDCB_ARCHIVE:
WinSendDlgItemMsg(hwnd,IDRB_ALSO,
BM_SETCHECK,
MPFROMSHORT(TRUE),NUL);
break;
case IDD_PATTERN:
if ( SHORT2FROMMP( mp1 ) == EN_CHANGE )
/* enable/disable search button */
WinEnableWindow(
WinWindowFromID( hwnd, IDD_SEARCH ),
WinQueryWindowTextLength(
WinWindowFromID( hwnd, IDD_PATTERN )));
else
fPassToDef = TRUE;
break;
default:
fPassToDef = TRUE;
break;
}
break;
case WM_THREAD_DONE:
usThreadCounter--;
/* When 0 all threads will have finished */
if (!usThreadCounter)
{
/* set status text message */
WinSetWindowText(WinWindowFromID(hwnd,IDT_STATUS),
"Press Search to start");
/* check for null search operation */
if ( !WinSendDlgItemMsg(
hwnd,
IDD_FILES,
LM_QUERYITEMCOUNT,
0L,
0L
) )
WinMessageBox(
HWND_DESKTOP,
hwnd,
"No files found matching criteria!",
"File Finder",
0,
MB_OK | MB_ICONHAND
);
/* change button text back to Search */
WinSetWindowText(
WinWindowFromID( hwnd, IDD_SEARCH ), "~Search");
fSearch = FALSE;
}
break;
case WM_COMMAND:
switch ( COMMANDMSG( &usMsg )->cmd ) {
case IDD_SEARCH: /* search using path */
case DID_OK:
if (!fSearch)
{
fSearch = TRUE;
/* change button text to Stop */
WinSetWindowText(WinWindowFromID( hwnd, IDD_SEARCH ),
"~Stop");
StartSearch(hwnd);
}
else
fContinue = FALSE;
break;
case IDD_QUIT:
fContinue = FALSE;
if (usThreadCounter)
WinPostMsg(hwnd,WM_COMMAND,
MPFROMSHORT(IDD_QUIT),
MPFROMSHORT(CMDSRC_PUSHBUTTON));
else
WinDismissDlg( hwnd, TRUE );
break;
case IDM_ABOUT:
WinDlgBox( HWND_DESKTOP, hwnd, AboutDlgProc, NUL, IDD_ABOUTDLG, NUL );
break;
case DID_CANCEL:
/* don't quit the program when escape key is pressed */
fContinue = FALSE;
break;
default:
fPassToDef = TRUE;
break;
}
break;
case WM_MEASUREITEM:
if ( SHORT1FROMMP( mp1 ) == IDD_FILES ) {
HPS hps; /* handle to window PS */
FONTMETRICS *pfm ; /* info on font */
int iLen;
pfm = malloc(sizeof(FONTMETRICS));
hps = WinGetPS( hwnd );
GpiQueryFontMetrics(hps, (long)sizeof(FONTMETRICS), pfm);
iLen = (int)(long)WinSendMsg(WinWindowFromID(hwnd,SHORT1FROMMP(mp1)),
LM_QUERYITEMTEXTLENGTH,
mp2, 0L);
iSaveLength = (iLen < iSaveLength ) ? iSaveLength : iLen;
/* return the height and length of the longest listbox item */
// mresRtnVal = MRFROM2SHORT( pfm->lMaxBaselineExt+2,(pfm->lMaxCharInc *iSaveLength) );
mresRtnVal = MRFROM2SHORT( pfm->lMaxBaselineExt+2, ((pfm->lAveCharWidth *iSaveLength)+(iSaveLength*2)) );
WinReleasePS( hps );
free(pfm);
}
break;
case WM_DRAWITEM:
if ( SHORT1FROMMP( mp1 ) == IDD_FILES ) {
int len;
COLOR clrFG, clrBG; /* Foreground/Background colors */
OWNERITEM FAR *oi = (OWNERITEM FAR *)mp2;
char *str = NULL;
len = (int)(long)WinSendMsg(oi->hwnd, LM_QUERYITEMTEXTLENGTH, MPFROMSHORT(oi->idItem), 0L);
if(len)
{
str = malloc(len);
if (str)
{
WinSendMsg(oi->hwnd, LM_QUERYITEMTEXT, MPFROM2SHORT(oi->idItem, len), MPFROMP(str));
if ((strstr(str,"File Error - ")) || (strstr(str,"LzhFile Error")))
{
if (oi->fsState != TRUE) /* should cell be highlited?*/
{
clrFG = CLR_BLACK;
clrBG = CLR_CYAN;
}
else
{
clrFG = CLR_CYAN;
clrBG = CLR_BLACK;
}
WinDrawText(oi->hps, len, str,
&oi->rclItem, clrFG, clrBG,
DT_LEFT | DT_VCENTER | DT_ERASERECT);
}
else
{
if (!strstr(str,"-->"))
{
if (oi->fsState != TRUE) /* should cell be highlited?*/
{
clrFG = CLR_DARKBLUE;
clrBG = CLR_WHITE;
}
else
{
clrBG = CLR_DARKBLUE;
clrFG = CLR_WHITE;
}
WinDrawText(oi->hps, len, str,
&oi->rclItem, clrFG, clrBG,
DT_LEFT | DT_VCENTER | DT_ERASERECT);
}
else
{
if (strstr(str,"ZIP-->"))
{
if (oi->fsState != TRUE) /* should cell be highlited?*/
{
clrFG = CLR_DARKRED;
clrBG = CLR_WHITE;
}
else
{
clrBG = CLR_DARKRED;
clrFG = CLR_WHITE;
}
WinDrawText(oi->hps, len, str,
&oi->rclItem, clrFG, clrBG,
DT_LEFT | DT_VCENTER | DT_ERASERECT);
}
else
if (strstr(str,"LZH-->"))
{
if (oi->fsState != TRUE) /* should cell be highlited?*/
{
clrFG = CLR_BLACK;
clrBG = CLR_WHITE;
}
else
{
clrBG = CLR_BLACK;
clrFG = CLR_WHITE;
}
WinDrawText(oi->hps, len, str,
&oi->rclItem, clrFG, clrBG,
DT_LEFT | DT_VCENTER | DT_ERASERECT);
}
else
if (strstr(str,"ARC-->") || strstr(str,"PAK-->"))
{
if (oi->fsState != TRUE) /* should cell be highlited?*/
{
clrFG = CLR_DARKGREEN;
clrBG = CLR_WHITE;
}
else
{
clrBG = CLR_DARKGREEN;
clrFG = CLR_WHITE;
}
WinDrawText(oi->hps, len, str,
&oi->rclItem, clrFG, clrBG,
DT_LEFT | DT_VCENTER | DT_ERASERECT);
}
}
}
free(str);
}
oi->fsState = oi->fsStateOld = FALSE;
}
return((MRESULT)TRUE);
}
break;
case WM_MINMAXFRAME:
{
PSWP pswp; /* pos change structure */
/* hide list box when minimized so it doesn't overwrite icon */
pswp = PVOIDFROMMP( mp1 );
WinShowWindow(
WinWindowFromID( hwnd, IDD_FILES ),
!(pswp->fs & SWP_MINIMIZE)
);
}
break;
default:
fPassToDef = TRUE;
break;
}
/* pass to def dialog proc if needed */
if ( fPassToDef )
mresRtnVal = WinDefDlgProc( hwnd, usMsg, mp1, mp2 );
return mresRtnVal;
}
/**/
/*
* AboutDlgProc( hwndDlg, usMsg, mp1, mp2 ) : MRESULT;
*
* hwndDlg handle to dialog box
* usMsg message number
* mp1 message parameter 1
* mp2 message parameter 2
*
* This is the dialog procedure for the About dialog box.
*
*/
MRESULT EXPENTRY AboutDlgProc( HWND hwndDlg, USHORT usMsg, MPARAM mp1, MPARAM mp2 )
{
MRESULT mresRtnVal; /* function return value */
BOOL fPassToDef; /* pass to def dlg proc? */
mresRtnVal = FALSE;
fPassToDef = FALSE;
switch ( usMsg ) {
case WM_INITDLG:
CenterPopup( hwndDlg, HWNDOWNER( hwndDlg ) );
break;
case WM_COMMAND:
switch ( COMMANDMSG( &usMsg )->cmd ) {
case DID_OK:
WinDismissDlg( hwndDlg, TRUE );
break;
default:
fPassToDef = TRUE;
break;
}
break;
default:
fPassToDef = TRUE;
break;
}
if ( fPassToDef )
mresRtnVal = WinDefDlgProc( hwndDlg, usMsg, mp1, mp2 );
return mresRtnVal;
}
/**/
/*
* CenterPopup( hwndPopup, hwndCenter ) : VOID;
*
* hwndPopup handle to popup window to center
* hwndCenter handle to window within which to center
*
* This function centers the popup window within the given window.
* To center within the entire desktop, pass HWND_DESKTOP as the
* hwndCenter parameter. If the centered popup would be partially
* or completely off the edges of the screen, it is moved to be
* within the borders of the screen.
*
*/
static VOID CenterPopup(
HWND hwndPopup,
HWND hwndCenter )
{
LONG cxPopup; /* popup width */
LONG cyPopup; /* popup height */
LONG cxCenter; /* parent width */
LONG cyCenter; /* parent height */
LONG cxScreen; /* screen width */
LONG cyScreen; /* screen height */
RECTL rclCenter; /* parent rectangle */
RECTL rclPopup; /* popup rectangle */
/* get window rects for popup and center */
if ( !hwndCenter || (hwndCenter == HWND_DESKTOP) ) {
rclCenter.xLeft = 0;
rclCenter.yBottom = 0;
rclCenter.xRight = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );
rclCenter.yTop = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN );
} else
WinQueryWindowRect( hwndCenter, &rclCenter );
WinQueryWindowRect( hwndPopup, &rclPopup );
/* convert to screen coordinates */
MAPWINDOWRECTS( hwndPopup, HWND_DESKTOP, &rclPopup, 1 );
MAPWINDOWRECTS( hwndCenter, HWND_DESKTOP, &rclCenter, 1 );
/* calculate window widths */
cxPopup = ABS(rclPopup.xRight - rclPopup.xLeft);
cyPopup = ABS(rclPopup.yTop - rclPopup.yBottom);
cxCenter = ABS(rclCenter.xRight - rclCenter.xLeft);
cyCenter = ABS(rclCenter.yTop - rclCenter.yBottom);
/* center popup within parent */
rclPopup.xLeft = rclCenter.xLeft + (cxCenter-cxPopup)/2;
rclPopup.yBottom = rclCenter.yBottom + (cyCenter-cyPopup)/2;
/* adjust position if hanging off on right or left */
cxScreen = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );
if ( rclPopup.xLeft+cxPopup >= cxScreen )
rclPopup.xLeft = (cxScreen - 1) - cxPopup;
if ( rclPopup.xLeft < 0 )
rclPopup.xLeft = 0;
/* adjust position if hanging off on top or bottom */
cyScreen = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN );
if ( rclPopup.yBottom+cyPopup >= cyScreen )
rclPopup.yBottom = (cyScreen - 1) - cyPopup;
if ( rclPopup.yBottom < 0 )
rclPopup.yBottom = 0;
/* convert to parent coordinates */
rclPopup.xRight = rclPopup.yTop = 0; /* don't care about topright */
MAPWINDOWRECTS( HWND_DESKTOP, HWNDPARENT( hwndPopup ), &rclPopup, 1 );
/* place popup window using parent coordinates */
WinSetWindowPos(
hwndPopup,
NUL,
LOUSHORT( rclPopup.xLeft ),
LOUSHORT( rclPopup.yBottom ),
0,
0,
SWP_MOVE
);
}
/*
* StartSearch( hwnd ) : VOID;
*
* hwnd handle to the dialog window
*
* This function starts the file search procedure.
* If archive file search is requested it will search the selected
* archive files for the pattern.
*
*/
void StartSearch(HWND hwnd)
{
USHORT iItem; /* temporary loop variable */
HWND hwndListBox; /* handle to list box */
CHAR szDrive[8]; /* drive specification string */
int i;
TID ScanTID ; /* scan thread id */
BOOL bArchive; /* search archives? */
BOOL bOnly ; /* only search archives? */
static SCANTHREADPARM stp;
usThreadCounter = 0;
/* set status text message */
WinSetWindowText(WinWindowFromID(hwnd,IDT_STATUS),
"Search in progress");
/* retrieve search pattern & erase current file list */
WinQueryDlgItemText(
hwnd,
IDD_PATTERN,
sizeof(stp.szPattern),
stp.szPattern
);
WinSendDlgItemMsg( hwnd, IDD_FILES, LM_DELETEALL, 0L, 0L );
/* search archives ? */
bArchive = SHORT1FROMMR(WinSendDlgItemMsg(hwnd,IDCB_ARCHIVE,
BM_QUERYCHECK,
NUL,NUL));
/* search only archives for mask ? */
bOnly = SHORT1FROMMR(WinSendDlgItemMsg(hwnd,IDRB_ONLY,
BM_QUERYCHECK,
NUL,NUL));
/* perform search on each selected drive */
i=0;
hwndListBox = WinWindowFromID( hwnd, IDD_DRIVES );
iItem = LIT_FIRST;
while (
(iItem = SHORT1FROMMR( WinSendMsg(
hwndListBox,
LM_QUERYSELECTION,
MPFROMSHORT( iItem ),
0L ) )) != LIT_NONE
) {
/* define file specification */
WinSendMsg(
hwndListBox,
LM_QUERYITEMTEXT,
MPFROM2SHORT( iItem, sizeof(szDrive) ),
MPFROMP( szDrive )
);
stp.drive_spec[i] = szDrive[2];
i++;
}
if(i<27)
stp.drive_spec[i] = NUL;
stp.hwndListBox = WinWindowFromID( hwnd, IDD_FILES );
stp.hwndDlg = hwnd;
/* A null archive field indicates regular search */
stp.szArchive[0] = NUL;
ScanTID = 0;
if (!bOnly)
{
DosSemSet(hsemWait);
if (-1==(ScanTID =_beginthread(ScanThread,NULL,STACKSIZE,&stp)))
WinAlarm(HWND_DESKTOP,WA_ERROR);
usThreadCounter++;
DosSemWait(hsemWait,(ULONG)-1) ;
}
/* if search archive then spin a thread to search */
if (bArchive)
{
/* perform search for each selected archive */
i=0;
hwndListBox = WinWindowFromID( hwnd, IDLB_ARCHIVE );
iItem = LIT_FIRST;
while (
(iItem = SHORT1FROMMR( WinSendMsg(
WinWindowFromID(hwnd,IDLB_ARCHIVE),
LM_QUERYSELECTION,
MPFROMSHORT( iItem ),
0L ) )) != LIT_NONE
) {
/* define file specification */
WinSendMsg(
WinWindowFromID(hwnd,IDLB_ARCHIVE),
LM_QUERYITEMTEXT,
MPFROM2SHORT( iItem, sizeof(stp.szArchive)),
MPFROMP( stp.szArchive ) );
if (-1==(ScanTID =_beginthread(ScanThread,NULL,STACKSIZE,&stp)))
WinAlarm(HWND_DESKTOP,WA_ERROR);
usThreadCounter++;
DosSemSetWait(hsemWait,-1);
}
}
}
void InitDlgBox(HWND hwnd)
{
HWND hwndSysMenu; /* system menu handle */
USHORT idSysMenu; /* system menu id */
MENUITEM miSysMenu; /* system menu item info */
MENUITEM miAbout; /* About menu item info */
USHORT usCurDrive; /* current drive number */
ULONG flDrives; /* available logical drives */
CHAR szDrive[6]; /* temporary drive string */
USHORT iItem; /* temporary loop variable */
USHORT cszList; /* # of selected drives */
static HWND hwndListBox; /* handle to list box */
/* add About item to system menu */
if ( hwndSysMenu = WinWindowFromID( hwnd, FID_SYSMENU ) ) {
/* get handle of system submenu */
idSysMenu = SHORT1FROMMR( WinSendMsg( hwndSysMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT( 0 ), 0L ) );
WinSendMsg( hwndSysMenu, MM_QUERYITEM, MPFROM2SHORT( idSysMenu, FALSE ), MPFROMP( &miSysMenu ) );
hwndSysMenu = miSysMenu.hwndSubMenu;
/* add menu separator */
miAbout.iPosition = MIT_END;
miAbout.afStyle = MIS_SEPARATOR;
miAbout.afAttribute = 0;
miAbout.id = 0;
miAbout.hwndSubMenu = NUL;
miAbout.hItem = NUL;
WinSendMsg( hwndSysMenu, MM_INSERTITEM, MPFROMP( &miAbout ), NUL );
/* add About item */
miAbout.afStyle = MIS_TEXT;
miAbout.id = IDM_ABOUT;
WinSendMsg( hwndSysMenu, MM_INSERTITEM, MPFROMP( &miAbout ), MPFROMP( "A~bout..." ) );
}
/* center dialog box on screen */
CenterPopup( hwnd, HWND_DESKTOP );
/* define search pattern */
WinSetDlgItemText( hwnd, IDD_PATTERN, "*.*" );
/* initialize drive list */
DosQCurDisk( &usCurDrive, &flDrives );
szDrive[0] = '[';
szDrive[1] = '-';
szDrive[3] = '-';
szDrive[4] = ']';
szDrive[5] = '\0';
for ( szDrive[2] = 'A'; szDrive[2] <= 'Z'; szDrive[2]++ ) {
if ( flDrives & 1 )
WinSendDlgItemMsg(
hwnd,
IDD_DRIVES,
LM_INSERTITEM,
MPFROMSHORT( LIT_END ),
MPFROMP( szDrive )
);
flDrives >>= 1;
}
/* select all fixed drives */
hwndListBox = WinWindowFromID( hwnd, IDD_DRIVES );
cszList = SHORT1FROMMR( WinSendMsg(
hwndListBox,
LM_QUERYITEMCOUNT,
0L,
0L
) );
for ( iItem = 0; iItem < cszList; iItem++ ) {
WinSendMsg(
hwndListBox,
LM_QUERYITEMTEXT,
MPFROM2SHORT( iItem, sizeof(szDrive) ),
MPFROMP( szDrive )
);
if ( szDrive[2] >= 'C' )
WinSendMsg(
hwndListBox,
LM_SELECTITEM,
MPFROMSHORT( iItem ),
MPFROMSHORT( TRUE )
);
}
/* disable cancel button */
WinEnableWindow(
WinWindowFromID( hwnd, IDD_CANCEL ), FALSE);
/* add the archive extensions to listbox */
WinSendDlgItemMsg(hwnd,
IDLB_ARCHIVE,
LM_INSERTITEM,
MPFROMSHORT( LIT_END ),
MPFROMP( "ZIP" ) );
WinSendDlgItemMsg(hwnd,
IDLB_ARCHIVE,
LM_INSERTITEM,
MPFROMSHORT( LIT_END ),
MPFROMP( "LZH" ) );
WinSendDlgItemMsg(hwnd,
IDLB_ARCHIVE,
LM_INSERTITEM,
MPFROMSHORT( LIT_END ),
MPFROMP( "ARC" ) );
WinSendDlgItemMsg(hwnd,
IDLB_ARCHIVE,
LM_INSERTITEM,
MPFROMSHORT( LIT_END ),
MPFROMP( "PAK" ) );
WinSendMsg( WinWindowFromID(hwnd,IDLB_ARCHIVE),
LM_SELECTITEM,
MPFROMSHORT( 0 ),
MPFROMSHORT( TRUE ) );
WinSetWindowText(WinWindowFromID(hwnd,IDT_STATUS),
"Press Search to start");
}